package com.gobuy.goods.advice;

import com.gobuy.common.pojo.Result;
import com.gobuy.common.pojo.StatusCode;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Gaozexi on 2020/6/10 21:49
 * Step by Step  and Stand on,  You Are The Best Investment!
 */
@Aspect
@Component
@RestController
public class GoodsServiceExceptionAspect   {
    private Logger logger = LoggerFactory.getLogger(GoodsServiceExceptionAspect.class);

    /**
     * 定义切入点，切入点为com.gobuy.goods下的所有函数
     */
    @Pointcut("execution(* com.gobuy.goods.service.impl.*.*(..))")
    public void  pt1(){
    }

    //@Before("pt1()")
    //public void doBefore (){
    //    System.out.println("前置增强");
    //}
    //
    //@After("pt1()")
    //public void doAfter (){
    //    System.out.println("前置增强");
    //}
    //
    //@AfterThrowing("pt1()")
    //public void doAfterThrowing (){
    //    System.out.println("前置增强");
    //}
    //
    //@Around("pt1()")
    //
    //public Result doAround(ProceedingJoinPoint pjp) {
    //    String simpleName = pjp.getTarget().getClass().getSimpleName();//获取类名
    //    String methodName = pjp.getSignature().getName();//获取方法名
    //    try {
    //        System.out.println(simpleName + "类的" + methodName + "方法执行前");
    //          pjp.proceed();
    //        return new Result(true, StatusCode.OK,"方法正常执行");
    //
    //
    //    } catch (Throwable throwable) {
    //        System.out.println(simpleName + "类的" + methodName + "方法出现异常,异常原因为：");
    //        System.out.println("throwable.getMessage() = " + throwable.getMessage());
    //        return new Result(true, StatusCode.ERROR, throwable.getMessage());
    //
    //    }
    //}
}
